#include <iostream>

class Animal
{
public:
    virtual void speak()
    {
        std::cout<<"动物叫"<<std::endl;
    }

    virtual ~Animal() //虚析构函数
    {
        std::cout<<"父类析构函数\n";
    }
};

class Dog:public Animal
{
public:
    void speak()
    {
        std::cout<<"汪汪汪"<<std::endl;
    }
};

class Cat:public Animal
{
public:
    void speak()
    {
        std::cout<<"喵喵喵"<<std::endl;
    }
};

void Show(Animal *a)
{
    a->speak();
}

int main()
{
    Animal *a = new Dog;
    Animal *b = new Cat;

    Show(a);
    Show(b);

    delete a;
    delete b;
    return 0;
}
